<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><s:text name="operCode.list.title"/></title>
	<%@ include file="/common/meta.jsp"%>
	<%@ include file="/common/common.jsp"%>
</head>
<body>
<div id="wrapper">
	<form>
	<div class="curmb"><s:text name="your.site.position"/>：<a href="${ctx}/main.action"><s:text name="homepage"/></a><span>></span><a href="#"><s:text name="operCode.title"/></a></div>
	<div class="listtit" id="listtit"><p><span><strong><s:text name="operCode.title"/></strong></span></p></div>
	<div class="proweroperate">
		<span class="space20"></span>
		 	
		<s:if test="ObjectType=='role'">
			<span class="rolename"><s:text name="operCode.role.name"/>:</span><s:property  value="jsonText"/>
			<span><s:text name="operCode.role.add"/></span>
		</s:if>
		<s:elseif test="ObjectType=='admin'">		
			<span class="adminname"> <s:text name="operCode.admin.loginName"/>:</span><s:property  value="jsonText"/>
			<span><s:text name="operCode.admin.add"/></span>
		</s:elseif>
	</div>
	<div class="listboxb" id="listbox">
		<div class="powerlist" id="powerlist">
			<p>
				<strong><s:text name="operCode.goble.setting"/></strong>
				<div class="powerbox"><ul>
				    <s:iterator  value="codeList.get(0)">
						<li><input type="checkbox"  id="<s:property value="operId"/>"  name="<s:property value="operType"/>"  value="<s:property value="operId"/>"/>
						<label for="<s:property value="operId"/>"><s:property value="operName"/>&nbsp;</label></li>
					</s:iterator>
				</ul>
				<div class="clear"></div>
				</div>
				
				<strong><s:text name="operCode.site.setting"/><span class="color#457d07"></span></strong>
				<div id="site_auth_div" class="powerbox"><ul>
					<s:iterator  value="codeList.get(1)">
						<li><input disabled="disabled" type="checkbox"  id="<s:property value="operId"/>"  name="<s:property value="operType"/>"  value="<s:property value="operId"/>"/>
						<label  id="<s:property value="operId"/>_hid"   class="powerchild" for="<s:property value="operId"/>"><s:property value="operName"/>&nbsp;</label></li>
						<input type="hidden" id="<s:property value="operId"/>_hidden_site" name="operCodeValue" value=""/>
					</s:iterator>
				</ul>
				<div class="clear"></div>
				</div>
			<div id="powertree">
				<strong><s:text name="operCode.cat.setting"/><span class="color#457d07"></span></strong>
				<div  id="cat_auth_div" class="powerbox"><ul>
					<s:iterator  value="codeList.get(2)">
						<li><input disabled="disabled" type="checkbox"  id="<s:property value="operId"/>"  name="<s:property value="operType"/>"  value="<s:property value="operId"/>"/>
						<label  id="<s:property value="operId"/>_hid"   class="powerchild" for="<s:property value="operId"/>"><s:property value="operName"/>&nbsp;</label></li>
						<input type="hidden"  id="<s:property value="operId"/>_hidden"  value="" name="operCodeValue"/>
					</s:iterator>
				</ul>
				<div class="clear"></div>
				</div>
			</div>	 
				<strong><s:text name="operCode.topic.setting"/><span class="color#457d07"></span></strong>
				<div id="topic_auth_div" class="powerbox"><ul>
					<s:iterator  value="codeList.get(3)">
						<li><input disabled="disabled" type="checkbox"  id="<s:property value="operId"/>"  name="<s:property value="operType"/>"  value="<s:property value="operId"/>"/>
						<label  id="<s:property value="operId"/>_hid"   class="powerchild" for="<s:property value="operId"/>"><s:property value="operName"/>&nbsp;</label></li>
						<input type="hidden" id="<s:property value="operId"/>_hidden_topic" name="operCodeValue" />
					</s:iterator>
				</ul>
				<div class="clear"></div>
				</div>	
				
				<strong>5、短信中心（全局）</strong>
				<div class="powerbox"><ul>
				    <s:iterator  value="codeList.get(4)">
						<li><input type="checkbox"  id="<s:property value="operId"/>"  name="<s:property value="operType"/>"  value="<s:property value="operId"/>"/>
						<label for="<s:property value="operId"/>"><s:property value="operName"/>&nbsp;</label></li>
					</s:iterator>
				</ul>
				<div class="clear"></div>
				</div>	
				<strong>6、OMS（全局）</strong>
				<div class="powerbox"><ul>
				    <s:iterator  value="codeList.get(5)">
						<li><input type="checkbox"  id="<s:property value="operId"/>"  name="<s:property value="operType"/>"  value="<s:property value="operId"/>"/>
						<label for="<s:property value="operId"/>"><s:property value="operName"/>&nbsp;</label></li>
					</s:iterator>
				</ul>
				<div class="clear"></div>
				</div>	
			</p>
		</div>
		<div class="btnbox">
		     <s:if test="%{authLicence('1_1_2,1_1_3')}"> <input type="button" value="<s:text name="save"/>"  class="btnlist2" id="saveas"/></s:if>
			 <s:else><input type="button" value="<s:text name="save"/>" disabled="disabled" class="btnlist2" id="saveas"/></s:else>
			<input type="button" value="<s:text name="cancleDo"/>"  class="btnlist2" id="close-page" />
		</div>
	</div>
</form>
</div>
<div id="lightbox" class="lightbox">
	<div class="lighttit"><p><span><input type="button" value="&nbsp;" id="lightclose" class="lightclose" /><strong><s:text name="operCode.title"/></strong></span></p></div>
	<div class="lightmain">
		 <input type="hidden"  id="auth_hidden_id" name="auth_hidden_id" value=""/>
		<div class="lightmaintit"><s:text name="operCode.choice"/></div>
		
		<div id="site_tree_div_cat"  class='ztree' style="overflow-y:auto;overflow-x:auto;height:400px;"></div>
		<div class="lightbtnbox"><input type="button" value="<s:text name="save"/>" id="lightsubmit" class="btnlist2" /><input type="button" value="<s:text name="return"/>" id="nobtn" class="btnlist2" /></div>
	</div>
</div>
<div id="lightboxb" class="lightbox">
	<div class="lighttit"><p><span><input type="button" value="&nbsp;" id="lightcloseb" class="lightclose" /><strong><s:text name="operCode.title"/></strong></span></p></div>
	<div class="lightmain">
		 <input type="hidden"  id="auth_hidden_idhh" name="auth_hidden_idhh" value=""/>
		<div class="lightmaintit"><s:text name="operCode.choice"/></div>
		
		<div id="site_tree_div_b"   class='ztree' style="overflow-y:auto;overflow-x:auto;height:400px;"></div>  
		</div>
		<div class="lightbtnbox"><input type="button" value="<s:text name="save"/>" id="lightsubmitb" class="btnlist2" /><input type="button"  value="<s:text name="return"/>" id="nobtnb"  class="btnlist2" /></div>
	</div>
</div>
<script type="text/javascript">
	var arra = $$.g("#site_auth_div label");
	 
	for (var i=0;i<arra.length;i++){
		arra[i].onclick = function(){
			$$.shade("#"+this.id,"#lightcloseb,#lightsubmitb,#nobtnb","#lightboxb");
		};	
	}
	
	var arra1 = $$.g("#topic_auth_div label");
	for (var i=0;i<arra1.length;i++){
		arra1[i].onclick = function(){
			$$.shade("#"+this.id,"#lightcloseb,#lightsubmitb,#nobtnb","#lightboxb");
		};	
	}
	
	var arra2 = $$.g("#cat_auth_div label");
	for (var i=0;i<arra2.length;i++){
		arra2[i].onclick = function(){
			$$.shade("#"+this.id,"#lightclose,#lightsubmit,#nobtn","#lightbox");
		};	
	}
</script>
</body>
</html>
<script type="text/javascript"  >
//全局      (admin/role 已知)
//{operId:operid1-operid2-operid3,targetIds:authority,targetType:1}
function goble_get(){ 
   	var arr = new Array();
   	var s =$("input[name='1']:checked");
   	if(s.length<=0) return arr;   
   	for(var i =0;i<s.length;i++){
   		arr.push("{operId:'"+$(s[i]).val()+"',targetIds:'authority',targetType:'1'}");
   	} 
   	return arr;
}   

//返回数组
//全局      (admin/role 已知) 站点示例 专题栏目相同
//[{operIds:onlyoneid,targetIds:site1-site2-site3,targetType:2},{},{},{},{}]
function others_get(){
	var arr = new Array();
	var s = $("input[name=operCodeValue]");
	if(s.length<=0) return arr;
	for(var i=0;i<s.length;i++){
		if($(s[i]).val()!='' && $(s[i]).val()!='' && $.trim($(s[i]).val())!=''){
			var id =$(s[i]).attr('id').split("_")[0]; 
			var targetType = $("#"+id).attr('name');
			var other = "{operId:'"+id+"',targetIds:'"+$(s[i]).val()+"',targetType:'"+targetType+"'}";
			arr.push(other);
		}
	}
	return arr;
}
//全局、其他的权限组合字符串
function all_get(){		
	var all = new Array();
    var  goble= goble_get();
	var others = others_get() ;
    arr = goble.concat(others);	 
	var str = arr.join(",");
	if(str){
		str = "["+str+"]";
	}
	return str; 
}

//读取权限的list页面回显 
$(function(){
	var auth_code ="<s:property value="authJsonText"/>";  
	if(auth_code == null || auth_code=='')  return ;
	var json = eval(auth_code); 
    for(var i=0;i<json.length;i++){ 
   		if(json[i].targetType == '2'){
   			$("#"+json[i].operId+"_hidden_site").val(json[i].targetIds);
   		}else if(json[i].targetType == '3'){
   			$("#"+json[i].operId+"_hidden").val(json[i].targetIds);
   		}else if(json[i].targetType == '4'){
   			$("#"+json[i].operId+"_hidden_topic").val(json[i].targetIds);
   		}
     	$("#"+json[i].operId).attr('checked',true);
   		
    }    
});
//权限页面的载入时执行的方法
$(function(){
	$("#close-page").click(function(){
		window.close();
	});
	
	$("#saveas").click(function(){
		var authJsonText = all_get();
			submitAuth(authJsonText,"<s:property value="ObjectType"/>","<s:property value="ObjectId"/>"); 
	});
	
	//每次弹出页面权限选择完毕后 将 公共div 置空
	$("#lightsubmit").bind("click",function(){	     
		var ids = getAllcheckedIds('site_tree_div_cat');
		 
			var id = $("#auth_hidden_id").val();		     
			if(id)$("#"+id).val(ids);
		 
		checkBoxIfCheked('auth_hidden_id');
		$("#auth_hidden_id").val(''); 
	});
	
	$("#lightsubmitb").bind("click",function(){
		var ids = getAllcheckedIds('site_tree_div_b');
		 
			var id =  $("#auth_hidden_idhh").val();			 
			if(id) $("#"+id).val(ids); 
	 
		checkBoxIfCheked('auth_hidden_idhh');
	    $("#auth_hidden_idhh").val('');
	   
	});
	
	$("#lightcloseb").bind("click",function(){ 
		checkBoxIfCheked('auth_hidden_idhh');
	});
	
	$("#nobtnb").bind("click",function(){
		checkBoxIfCheked('auth_hidden_idhh');
	});
	
	$("#lightclose").bind("click",function(){ 
		checkBoxIfCheked('auth_hidden_id');
	});
	
	$("#nobtn").bind("click",function(){
		checkBoxIfCheked('auth_hidden_id');
	});
	
   //站点级别权限选择 弹出页
	$("#site_auth_div").find("label[class='powerchild']").each(function(i,item){
		$(item).bind("click",function(){
			var  id= $(item).attr('id');
			$("#auth_hidden_idhh").val(id+'den_site');
			loadAllSite(id);
		});
	});
 
	// 栏目级别的权限选择弹出页面 
	$("#cat_auth_div").find("label[class='powerchild']").each(function(i,item){
		$(item).bind("click",function(){
			var  id= $(item).attr('id'); 
			$("#auth_hidden_id").val(id+"den");			 
			loadAllCategory(id);		
		});
	});
	// 专题级别的权限选择弹出页面 
	$("#topic_auth_div").find("label[class='powerchild']").each(function(i,item){
		$(item).bind("click",function(){
			var  id= $(item).attr('id');
			$("#auth_hidden_idhh").val(id+'den_topic');		 
			loadAllTopic(id);
		});
	});
 
});
//权限提交
function submitAuth(authJsonText,objectType,objectId){
	$.ajax({
		url:"${ctx}/system/opercode-auth.action?t="+new Date().getTime() ,
		type:"post",
		dataType:"text",
		data:{"authJsonText":authJsonText,"objectType":objectType,"objectId":objectId},
		success:function(data){
			var json= eval('('+data+')');
			alert(json.msg);
			window.close();
		}
	});
}

//站点级 权限选择弹出,并且回显
function loadAllSite(triggerId){
	loadSitetree('site_tree_div_b');
	var s = $("#"+triggerId+"den_site").val();
	treeReshow(triggerId ,'site_tree_div_b',s);
} 
function  loadAllTopic(triggerId){
	loadTopictree('site_tree_div_b');
	var s = $("#"+triggerId+"den_topic").val();
	treeReshow(triggerId ,'site_tree_div_b',s);
}

function  loadAllCategory(triggerId){
	loadCatetree('site_tree_div_cat');
	var s = $("#"+triggerId+"den").val();
	treeReshow(triggerId ,'site_tree_div_cat',s);
}

function  treeReshow(triggerId ,treeId,jsonAuth){	
	if(jsonAuth){ //回显
		var arr = jsonAuth.split('-');
		var treeObj = $.fn.zTree.getZTreeObj(treeId);
		for(var i=0;i<arr.length;i++){
			var node = treeObj.getNodeByParam("id",arr[i], null);
			node.checked = true;
			treeObj.updateNode(node);
		}
		
	}
} 

function popSiteCheckedValue(){
	
	var arr = new Array();
	$("input[name='pop_site_name']:checked").each(function(j,item){
		arr.push($(item).val()); 
	});
	var str = arr.join('-');
	var id = $("#auth_hidden_idhh").val();   
	$("#"+id).val(str);
	id = id.replace('_hidden', '');
	if(str || $.trim(str)!=''){		 
		$("#"+id).attr('checked',true);
	}else{
		$("#"+id).attr('checked',false);
	}
}
 
function getAllcheckedIds(treeId){
	var treeObj = $.fn.zTree.getZTreeObj(treeId);
	var nodes = treeObj.getCheckedNodes(true);
	var array_z = new Array();
	if(nodes){
		for(var i=0; i<nodes.length;i++){
			array_z.push(nodes[i].id);
		}		  
		return array_z.join("-");
	}	  
} 
 
//是否有权限已经被选中 
function checkBoxIfCheked(e_id){  
	var id = $("#"+e_id).val(); //4028839c30307704013030d69d400006_hidden
	if(id && $.trim(id)!=''){ 
        var v = $("#"+id).val();  // 权限值 
        id = id.split("_")[0];  // id=4028839c30307704013030d69d400006
        if(v &&  $.trim(v)!=''){ 
        	$("#"+id).attr('checked',true);        	 
        }else{
    		$("#"+id).attr('checked',false);	
    	} 
	}
}
</script>
<link href="${ctx}/css/zTreeStyle/zTreeStyle.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="${ctx}/js/jquery.ztree.core-3.0.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery.ztree.excheck-3.0.js"></script>
<script type="text/javascript"> 
var setting = {
		check: {
			enable: true,
			chkStyle: "checkbox",
			chkboxType :{Y:'s',N:'s'}
		},
		data: {
			simpleData: {
				enable: true
			}
		} 
	};	 
function loadCatetree (id){	
	$.ajax({
		async:false, 
		url:"${ctx}/site/authsite.action?t="+new Date().getTime(),		 
		type:"post",
		dataType:"text",
		success:function(ss){
			var zNodes = eval('('+ss+')');
			$.fn.zTree.init($("#"+id), setting, zNodes);
			 
		}
	});
} 
function loadSitetree (id){	
	$.ajax({
		async:false, 
		url:"${ctx}/site/site-loadallsite.action?t="+new Date().getTime(),		 
		type:"post",
		dataType:"text",
		success:function(ss){
			var zNodes = eval('('+ss+')');
			$.fn.zTree.init($("#"+id), setting, zNodes);
			 
		}
	});
}
function loadTopictree (id){	
	$.ajax({
		async:false, 
		url:"${ctx}/site/site-loadalltopic.action?t="+new Date().getTime(),
		data:{'allSite':true},		
		type:"post",
		dataType:"text",
		success:function(ss){
			var zNodes = eval('('+ss+')');
			$.fn.zTree.init($("#"+id), setting, zNodes);
			 
		}
	});
}
</script>